package com.lp.service.impl;

import com.lp.dao.CommentDao;
import com.lp.dao.SceneryDao;
import com.lp.po.Comment;
import com.lp.po.PagingVO;
import com.lp.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Resource
    private CommentDao commentDao;
    @Resource
    private SceneryDao sceneryDao;

    @Override
    public int getCommentCount() throws Exception {
        return commentDao.count();
    }

    @Override
    public int getCountWithStudent(Integer studentid) throws Exception {
        return commentDao.countWithStudent(studentid);
    }

    @Override
    public List<Comment> findComment(Integer toPageNo) {
        PagingVO pagingVO = new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        List<Comment> list=commentDao.findComment(pagingVO);
        return list;
    }

    @Override
    public List<Comment> findCommentWithStudent(Integer studentid,Integer toPageNo) {
        PagingVO pagingVO = new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        List<Comment> list=commentDao.findCommentWithStudent(pagingVO.getTopageNo(),pagingVO.getPageSize(),studentid);
        return list;
    }
    @Override
    public Comment findById(Integer id) {
        Comment list=commentDao.findByCommentId(id);
        return list;
    }

    @Override
    public void updataComment(String zhanshi,Integer id) {
        commentDao.updataCommentWithZhanshi(zhanshi,id);
    }

    @Override
    public void delectcomment(Integer id) {
        commentDao.delectComment(id);
    }


    /************************小程序端**********************************/
    @Override
    public void insetContent(String content, Integer studentid, Integer sceneryid, String nowtime,Integer grade) {
        Comment comment=new Comment();
        comment.setContent(content);
        comment.setStudentid(studentid);
        comment.setSceneryid(sceneryid);
        comment.setNowtime(nowtime);
        commentDao.insetContent(comment);

        int newGrade=grade+1;
        sceneryDao.addGradeWithSceneryId(sceneryid,newGrade);
        System.out.println("服务层："+newGrade);
        System.out.println("服务层sceneryid："+sceneryid);
    }



    @Override
    public List<Comment> wxSelectComment(Integer sceneryid) {
        return commentDao.wxSelectComment(sceneryid);
    }
}
